package com.myedusys.mapper;

import com.myedusys.annotation.AutoFill;
import com.myedusys.enumeration.OperationType;
import entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {


    /**
     * 根据用户名找用户
     * @param username
     * @return
     */
    @Select("select * from user where username = #{username}")
    User findByUserName(String username);

    /**
     * 注册用户
     * @param username
     * @param password
     */
    @Insert("insert into user(username,password,create_time,update_time) " +
            "values(#{username},#{password},now(),now())")
    void save(String username, String password);

    @Select("select * from user where id=#{id}")
    User findById(Long id);

    @AutoFill(OperationType.UPDATE)
    void update(User user);

    @AutoFill(OperationType.UPDATE)
    @Update("update user set user_pic = #{userPic} where id = #{id}")
    void updateAvatar(String userPic,Long id);

}
